import HTTP from '@/plugins/axios'
import {
  Advise,
  Area,
  dealRes,
  LoginFormInterface,
  MenuList,
  Notice,
  pageList,
  Password,
  RoomDto,
  Staff,
  tokenResult,
  Vol,
  Volunteer
} from '@/ts/type'
import { api } from '@/ts/enum'

// 登录系列的接口
export class LoginService {
  // 登录接口
  static login(params: LoginFormInterface) {
    return HTTP.post<tokenResult>('/login', params)
  }

  // 获取登录用户的信息
  static info() {
    return HTTP.get<dealRes<Staff>>('/info')
  }

  // 退出登录
  static logout() {
    return HTTP.post<string>('/logout')
  }
}

// 菜单系列的接口
export class MenuService {
  // 获取菜单接口
  static menuList() {
    return HTTP.get<dealRes<MenuList[]>>('/menu')
  }
}

// 公告系列的接口
export class NoticeService {
  // 根据id获取公告信息
  static selectByPrimaryKey(id: number) {
    return HTTP.get<dealRes<Notice>>(`/${api.NoticeApi}/${id}`)
  }

  // 模糊分页查询公告
  static getNotices(page: number, size: number, params: Notice) {
    return HTTP.post<dealRes<pageList<Notice>>>(`/${api.NoticeApi}/${page}/${size}`, params)
  }

  // 获取公告接口
  static getNoticeList() {
    return HTTP.get<Notice[]>(`/${api.NoticeApi}`)
  }

  // 根据id删除公告
  static deleteNotice(id: number) {
    return HTTP.delete<dealRes<string>>(`/${api.NoticeApi}/${id}`)
  }

  // 新建公告
  static postNotice(params: Notice) {
    return HTTP.post<dealRes<string>>(`/${api.NoticeApi}`, params)
  }

  // 修改公告
  static putNotice(params: Notice) {
    return HTTP.put<dealRes<string>>(`/${api.NoticeApi}`, params)
  }

  // 分页查询
  static noticePage(page: number, size: number) {
    return HTTP.get<dealRes<pageList<Notice>>>(`/${api.NoticeApi}/${page}/${size}`)
  }
}

// 建议系列的接口
export class AdviseService {
  // 模糊分页查询
  static inquiry(params: Advise, page: number, size: number) {
    return HTTP.post<dealRes<pageList<Advise>>>(`/${api.AdviseApi}/${page}/${size}`, params)
  }

  // 根据id获取公告信息
  static selectByPrimaryKey(id: number) {
    return HTTP.get<dealRes<Advise>>(`/${api.AdviseApi}/${id}`)
  }

  // 分页查询
  static advisePage(page: number, size: number) {
    return HTTP.get<dealRes<pageList<Advise>>>(`/${api.AdviseApi}/${page}/${size}`)
  }

  // 提交建议回复
  static postAdvise(params: Advise) {
    return HTTP.put<dealRes<string>>(`/${api.AdviseApi}`, params)
  }

  // 提交建议
  static postAdvises(data: Advise) {
    return HTTP.post<dealRes<string>>(`/${api.AdviseApi}`, data)
  }
}

// 管理人员的相关接口
export class StaffService {

  // 修改管理员信息
  static putStaff(params: Staff) {
    return HTTP.put<dealRes<Staff>>(`/${api.StaffApi}`, params)
  }

  // 修改管理员密码
  static changePwd(params: Password) {
    return HTTP.put<dealRes<string>>(`/${api.StaffApi}/pwd`, params)
  }
}

// 房区相关的接口
export class AreaService {

  // 获取房区列表
  static getList() {
    return HTTP.get<dealRes<Area[]>>(`/${api.AreaApi}`)
  }

  // 更新房区列表
  static updateList(params: Area) {
    return HTTP.put<dealRes<string>>(`/${api.AreaApi}`, params)
  }

  // 获取已启用的房区信息
  static getOption() {
    return HTTP.get<dealRes<Area[]>>(`/${api.AreaApi}/option`)
  }

  // 获取已启用的房区信息
  static getOptions() {
    return HTTP.get<dealRes<Area[]>>(`/${api.AreaApi}/options`)
  }
}

// 病房相关的接口
export class RoomService {

  // 获取病房列表
  static getList(page: number, size: number) {
    return HTTP.get<dealRes<pageList<RoomDto>>>(`/${api.RoomApi}/${page}/${size}`)
  }

  // 修改病房的状态
  static changeDisinfection(id: number, name: string, bool: boolean) {
    return HTTP.post<dealRes<string>>(`/${api.RoomApi}/disinfection`, { id, name, bool })
  }

  // 通过id获取病房列表
  static getListById(page: number, size: number, name: string) {
    return HTTP.get<dealRes<pageList<RoomDto>>>(`/${api.RoomApi}/${page}/${size}/${name}`)
  }

  // 通过id修改房间备注
  static putRoomRemark(roomId: number, roomRemark: string) {
    return HTTP.put<dealRes<string>>(`/${api.RoomApi}`, { roomId, roomRemark })
  }
}

// 志愿者相关的接口
export class VolunteerService {
  static getList(page: number, size: number) {
    return HTTP.get<dealRes<pageList<Volunteer>>>(`/${api.VolunteerApi}/${page}/${size}`)
  }

  static deleteVolunteer(id: number) {
    return HTTP.delete<dealRes<string>>(`/${api.VolunteerApi}/${id}`)
  }

  static statusChange(id: number, name: string, bool: boolean) {
    return HTTP.put<dealRes<string>>(`/${api.VolunteerApi}/status`, { id, name, bool })
  }

  static addVol(data: Vol) {
    return HTTP.post<dealRes<string>>(`/${api.VolunteerApi}`, data)
  }

  static queryVol(page: number, size: number, data: Vol) {
    return HTTP.post<dealRes<pageList<Volunteer>>>(`/${api.VolunteerApi}/query/${page}/${size}`, data)
  }

  static getVolById(id: number) {
    return HTTP.get<dealRes<Vol>>(`/${api.VolunteerApi}/${id}`)
  }

  static putVol(data: Vol) {
    return HTTP.put<dealRes<string>>(`/${api.VolunteerApi}`, data)
  }
}